<?php

/**
 * @author ducnhat
 * @email ddnhat@gmail.com
 * @copyright 2014
 */
 
class IndexController extends Zenddn_Controller_Action{
    
    public function init(){
        parent::init();
        parent::loadTemplate('magashop');
        $this->view->page = "home";
    }
    
    public function indexAction(){
        $model = new Default_Model_Product();
        $data = $model->getAllData();
        
        $this->view->data = $data;
    }
    
    public function detailAction(){
        $request = $this->_request;
        
        $id = $request->getParam('id', false);
        
        $cache = new Zenddn_System_Cache();
        $cache = $cache->getCache();        
        $cache_id = "getData_$id";
        
        $model = new Default_Model_Product();
        
        if(($data = $cache->load($cache_id)) === false){
            $data = $model->getData($id);
            $cache->save($data, $cache_id, array('product'));
        }
        
        $relatedData = $model->getRelatedData($data['brand_id']);
        $otherData = $model->getOtherData($data['brand_id']);
        
        $this->view->otherData = $otherData;
        $this->view->relatedData = $relatedData;
        $this->view->data = $data;
    	$layout = $this->_helper->layout()->setLayout('product-detail');
        $this->view->page = "";
    }
}